export function debounce(fn, delay, immediate) {
  let timer = null
  return function() {
    var args = arguments
    var _self = this
    if (timer) clearTimeout(timer)
    if (immediate) {
      timer = setTimeout(function() {
        timer = null
      }, delay)
      fn.apply(_self, args)
    } else {
      timer = setTimeout(function() {
        fn.apply(_self, args)
      }, delay)
    }
  }
}

export function throttle(fn, wait) {
  let timeout
  return function() {
    var args = arguments
    var _self = this
    if (!timeout) {
      timeout = setTimeout(() => {
        timeout = null
        fn.apply(_self, args)
      }, wait)
    }
  }
}
// export function deepClone (origin, target) {
//   var target = target || {}
//   var toStr = Object.prototype.toString
//   var arrStr = '[object Array]'
//   for(let prop in origin) {
//     if (origin.hasOwnProperty(prop)) {
//       if (typeof origin[prop] == 'object' && origin[prop] !== null) {
//        if (toStr.call(origin[prop]) == arrStr){
//           origin[prop] = []
//        } else {
//         origin[prop] = {}
//       }
//       deepClone (origin[prop], target[prop])
//     }else {
//       target[prop] = origin[prop]
//     }
//   }
// }
// console.log(origin, target)
// return target;
// }
